<%@page import="com.szboanda.platform.common.utils.StringUtils"%>
<%@ include file="/platform/common/header.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ page import="com.szboanda.platform.v3.workflow.jdbc.JDBCUsersCache"%>
<%@ page import="com.szboanda.platform.v3.util.log.load.RelativeDateFormat"%>
<%@ page import="java.util.Date"%>
<link href="<common:webRoot />/resources/platform/oldworkflow/css/oldworkflow.css" rel="stylesheet" type="text/css">
<style>
	.container-full .activeTab{background-color: #0dbe00;color: white;outline: none;border: 1px solid #0dbe00}
	.buttonTab:hover,
	.buttonTab:focus{background-color: #0dbe00;color: white;outline: none;border: 1px solid #0dbe00}
	.btn-default{
		outline: none;border: 1px solid #e8e8e8;
	}
</style>
<body ng-init="pageTitle='办理详情'; workflowId='${workflowId}'; workflowDefId='${workflowDefId}';" style="overflow: hidden">
<div class="container-full" ng-controller="ProcessController" style="height: 100%">
    <p style="position: absolute; top:3px; right: 10px;">
		<button class="button btn btn-default buttonTab" ng-class="{true: 'activeTab', false: 'inactive'}[isActive]" ng-click="switchProcess(true)">办理过程</button>
		<button class="button btn btn-default buttonTab" ng-class="{true: 'activeTab', false: 'inactive'}[!isActive]" ng-click="switchProcess(false)">流程图</button>
	</p>
	<div class="stepContent" style="height: 100%;overflow: auto" ng-show="showProcess">
		<div class="finishedSteps">
			<jsp:useBean id="now" class="java.util.Date" scope="request" />
			<table class="stepTable" width="100%" border="0" cellpadding="0"
				cellspacing="0">
				<c:forEach items="${steps }" var="step">
					<c:set value="${step.key }" var="stepInfo" />
					<c:set value="${step.value }" var="processInfos" />
					<c:set var="finish" value="0" />
					<c:set var="master" value="0" />
					<c:forEach items="${processInfos }" var="process">
						<c:set var="isReader"
							value="${process.processType == 'READER' || process.processType == 'HELPER'}"
							scope="request" />
						<c:if test="${empty startTime}">
							<c:set var="startTime" value="${process.begin }" scope="request" />
						</c:if>
						<c:if test="${!isReader}">
							<c:set var="master" value="${master + 1 }" />
						</c:if>
						<c:if test="${!sReader && process.state == 'Finished' }">
							<c:set var="finish" value="${finish + 1 }" />
							<c:set var="endTime" value="${process.end }" scope="request" />
						</c:if>
					</c:forEach>
					<c:if test="${master > 0 && master > finish  }">
						<c:set var="endTime" value="${now }" scope="request" />
					</c:if>
					<tr class="step-content"
						parallel="${stepInfo.parents eq  prevParent}">
						<td class="time" valign="top"><c:set var="prevParent"
								scope="request" value="${stepInfo.parents }" /> <%
     request.setAttribute("stepDate", RelativeDateFormat.format((Date) request.getAttribute("startTime"),
 						(Date) request.getAttribute("endTime"), false));
 %>
							<div class="step-name">${stepInfo.definition.stepDesc }<c:if
									test="${'sendback' eq stepInfo.generateType }">
									<span class="backImg">&nbsp;</span>
								</c:if>
							</div> <span class="time-span">${stepDate}</span>
							<div class="step-line">
								<div class="line"></div>
							</div></td>
						<td class="opinion" valign="top"><c:forEach
								items="${processInfos }" var="process" varStatus="stat">
								<c:set var="userId" value="${process.processer }"
									scope="request" />
								<c:set var="originalProcesser" value="${process.originalProcesser }"
									scope="request" />
								<%
									// 适配AB角场景, 展示形式：A角 (B角代) add by 蔡楚涛  2018-09-25
									String processer = JDBCUsersCache.getInstance().getUser(request.getAttribute("userId").toString()).getUserName();
									if (StringUtils.hasText((String) request.getAttribute("originalProcesser"))) {
									    String originalProcesser = JDBCUsersCache.getInstance().getUser(request.getAttribute("originalProcesser").toString()).getUserName();
									    processer = processer + " (" + originalProcesser +"代)";
									}
								    request.setAttribute("processer", processer);
								%>
								<c:set var="isReader"
									value="${process.processType == 'READER' || process.processType == 'HELPER'}"
									scope="request" />
								<div class="desc ${isReader ? 'reader' : 'master'}">
									<span class="step-processer" title="${processer }">${processer }</span>
									<c:if test="${process.state == 'Finished' || process.state == 'Wait' }">
										<c:set var="processEnd" value="${process.end }"
											scope="request" />
										<span class="step-time"><fmt:formatDate
												value="${process.end}" pattern="yyyy-MM-dd HH:mm" /></span>
										<c:if test="${not empty process.description }">
											<span class="agree" title="${process.description }"><span
												class="desc">${process.description }</span><i>&nbsp;</i></span>
										</c:if>
									</c:if>
									<c:if test="${process.state == 'Underway' }">
										<span class="step-time dealing">处理中...</span>${process.remark }</c:if>
									<c:if test="${process.state == 'Queued' }">
										<span class="step-time dealing">排队中...</span>
									</c:if>
									<c:if test="${process.state == 'WaitFeedback' }">
										<span class="step-time dealing">等待返回...</span>
									</c:if>
									<c:if test="${process.state == 'SomeFeedback' }">
										<span class="step-time dealing">部分人返回...</span>
									</c:if>
									<c:if test="${process.state == 'AllFeedback' }">
										<span class="step-time dealing">所有人返回...</span>
									</c:if>
									<c:if test="${process.state == 'AlreadyFeedback' }">
										<span class="step-time dealing">已经返回...</span>
									</c:if>
									<c:if test="${process.state != 'Underway' &&  !isReader && stepRevokeInfo[process.stepId]}">
										<span id="${process.stepId}" class="step-revoke"
											onclick="finishedSteps.revoke({'LCSLBH':'${process.workflowId}','LCBH':'${stepInfo.definition.workflowDefinition.flowType}','BZDYBH':'${process.stepDefId}','BZBH':'${process.stepId}','SHOW':'DONESTEP','processer':'${process.processer}','processType':'${process.processType}'})"
											data-info="${stepInfo.definition.workflowDefinition.flowType}###${process.workflowId}###${process.stepDefId}###${process.stepId}">
										</span>
									</c:if>
								</div>
							</c:forEach></td>
					</tr>
				</c:forEach>
				<c:set value="${workflowInfo.workflowState }" var="workflowState"
					scope="request" />
				<c:if test="${workflowState ne 'Finished' }">
					<tr class="title step-send-back">
						<td class="name" colspan="2">
							<div style="float: left; width: 120px; text-align: center; color: #307FE3;">未结束</div>
							任务期限为：<b class="deal-user">${limitDate }</b>，
							已用时：<b class="deal-time">${useDate }</b>，${limitInfo }。</td>
					</tr>
				</c:if>
			</table>
		</div>
	</div>
    <div ng-show="showGraphics" style="height: 100%">
        <iframe id="graphicsFrame" scrolling="yes" src="" frameborder="0"
                style="width: 100%;"></iframe>
    </div>
</div>
	<%-- <c:if test="${empty param.BZBH}">
		<c:if test="${not empty actions && showAction}">
			<div class="actionImg">
				<img src="<common:webRoot />/resources/platform/oldworkflow/images/actionMenu.png" height="22px" style="cursor: pointer; position:relative; top : 4px;"/>
                <span style="position:relative; top : 5px; right: 5px; color: blue; cursor: pointer;">查看动作</span>
			</div>
			<div class="actionDiv">
				<c:forEach items="${actions}" var="item">
					<button
						onclick="showAction(this,'${ctx}/${item.actionDefinitionUrl}','${item.actionId}','${workflowInfo.workflowId}','${workflow.workflowDefinition.flowType}','${businessId}','${item.actionType}','${item.readonly}','${item.selfReadOnly}')">${item.actionName}</button>
				</c:forEach>
			</div>
		</c:if> 
	</c:if> --%>
	<script type="text/javascript" src="<common:webRoot/>/resources/platform/oldworkflow/workflow-v2.js?v=${sysversion}"></script>
	<script type="text/javascript" src="<common:webRoot/>/resources/platform/oldworkflow/generatorHelp.js?v=${sysversion}"></script>
	<script type="text/javascript" src="<common:webRoot/>/resources/platform/common/js/workflow.js?v=${sysversion}"></script>
	<script type="text/javascript">
$(function(){
	<c:if test="${empty param.BZBH}">
		$('.easyui-tabs').tabs({
		    height:$(window).height(),
		    onSelect:function(title,index){
		    	if('内容详情' == title){
					console.info($("#stepContent").attr("src"));
		    		if($("#stepContent").attr("src") == ""){
		    			//$("#stepContent").attr("src","${ctx }/${workflow.workflowDefinition.contentPage}?LCBH=${workflow.workflowDefinition.flowType}&LCSLBH=${workflow.workflowInfo.workflowId}&businessId=${businessId}&BZBH=${stepInfo.stepId}&BZDYBH=${stepInfo.stepDefId}")
		    			$("#stepContent").attr("src",
		    					Common.webRoot() + "/${workflow.workflowDefinition.contentPage}/${workflow.workflowDefinition.flowType}/${workflow.workflowInfo.workflowId}/${stepInfo.stepDefId}/${stepInfo.stepId}/show")
		    		}
		    	}
		    }
		});
		$("#stepContent").height($(window).height() - 35);
	</c:if>
	finishedSteps.init();
	
	if(${not empty actions && showAction}){
		var _arr = [];
		<c:forEach items='${actions}' var='item'>
	        _arr.push({
	                'text': '${item.actionName}',
	                'url': '${item.actionDefinitionUrl}',
	                'actionId': '${item.actionId}',
	                'lcbh': '${workflowInfo.workflowId}',
	                'lcdybh': '${workflow.workflowDefinition.flowType}',
	                'businessId': '${businessId}',
	                'actionType': '${item.actionType}',
	                'actionReadOnly': '${item.readonly}',
	                'selfReadOnly': '${item.selfReadOnly}',
	        });
		</c:forEach>
		var actionData = {'actions': _arr, 'isShow': ${showAction}}
		window.parent.helper.showActionDiv(actionData);
		/* $(".actionImg, .actionDiv").hover(function(){
			$(".actionDiv").show();
		}, function(){
			$(".actionDiv").hide();
		}); */
	}
});

/* function showAction(obj,url,actionId,lcbh,lcdybh,businessId,actionType,actionReadOnly,selfReadOnly){
	if(url != ""){
		url = Common.webRoot() + url;
		if(url.indexOf('?') > -1){
			url += "&";
		}else{
			url += "?";
		}
		url += "actionId=" + actionId;
		url += "&LCBH="+ lcbh;
		url += "&LCDYBH="+ lcdybh;
		url += "&businessId="+ businessId;
		url += "&actionType="+actionType;
		url += "&SFZD="+actionReadOnly;
		url += "&DZZSZD="+selfReadOnly;
		if(url.indexOf("fullScreen=true") != -1){
			workflow.openWin(url,window.screen.availWidth,window.screen.availHeight);
		}else{
			workflow.openWin(url, 800, 600);
		}
	}else{
		var text = obj.innerText || obj.textContent;
		Common.dialog({
			type: 'alert',
			content: '尚未配置[' + text + ']的链接',
		});
	}
} */
</script>
	<script type="text/javascript"
		src="<common:webRoot/>/resources/platform/oldworkflow/stepshistory.js"></script>
</body>
<%@ include file="/platform/common/footer.jsp"%>